﻿// CDiaTrainTG.cpp: 实现文件
//

//#include "pch.h"
#include "stdafx.h"
#include "DefectInspectionSystem.h"
#include "CDiaTrainTG.h"
#include "afxdialogex.h"
#include "DefectInspectionSystemDlg.h"

// CDiaTrainTG 对话框

IMPLEMENT_DYNAMIC(CDiaTrainTG, CDialogEx)

CDiaTrainTG::CDiaTrainTG(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_TG, pParent)
	, m_nbinaryThresh(0)
{
	m_bIsReadImage = FALSE;
	m_bIsExtractRegionCup = FALSE;
	m_bIsAutoThresh = FALSE;
	m_bIsTrainFibished = FALSE;
	nIndexShowImageBack = 0;
	m_nProductIsCircle = 1;

	GenEmptyRegion(&ho_RegionInterference);
}

CDiaTrainTG::~CDiaTrainTG()
{
}

void CDiaTrainTG::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDITROITHRESHOLD, m_nbinaryThresh);
}


BEGIN_MESSAGE_MAP(CDiaTrainTG, CDialogEx)
	ON_BN_CLICKED(IDC_BTN_PATH, &CDiaTrainTG::OnBnClickedBtnPath)
	ON_BN_CLICKED(IDC_BUTTON11, &CDiaTrainTG::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON_BACK_ABN_TRAIN, &CDiaTrainTG::OnBnClickedButtonBackAbnTrain)
	ON_WM_CLOSE()
	ON_WM_MOUSEWHEEL()
	ON_BN_CLICKED(IDC_BTN_SAVE, &CDiaTrainTG::OnBnClickedBtnSave)
	ON_BN_CLICKED(IDC_BUTTON_MeanImage, &CDiaTrainTG::OnBnClickedButtonMeanimage)
	ON_BN_CLICKED(IDC_BUTTON_VarImage, &CDiaTrainTG::OnBnClickedButtonVarimage)
	ON_BN_CLICKED(IDC_BUTTON_Interference, &CDiaTrainTG::OnBnClickedButtonInterference)
END_MESSAGE_MAP()


BOOL CDiaTrainTG::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	m_pWnd = GetDlgItem(IDC_IMAGE_VIEW);
	CRect rect;
	m_pWnd->GetClientRect(rect); //获取窗口大小
	OpenWindow(0, 0, rect.Width(), rect.Height(), (Hlong)(m_pWnd->m_hWnd), "visible", "", &m_hvWindow);
	UpdateUI();

	char tmpstr[MAX_PATH];
	CString strTemp;
	GetPrivateProfileString("DTG", "binaryThresh", "80", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	m_nbinaryThresh = atoi(tmpstr);
	GetPrivateProfileString("DTG", "productIsCircle", "80", tmpstr, MAX_PATH, theApp.m_strFilePath + "\\System-" + pDia->m_strCurrentCupType + ".ini");
	m_nProductIsCircle = atoi(tmpstr);
	UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CDiaTrainTG::OnBnClickedBtnPath()
{
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "位图文件| *.jpg;*.bmp|All Files (*.*)|*.*|", NULL);
	dlg.m_ofn.lpstrInitialDir = theApp.m_strFilePath;
	if (dlg.DoModal() == IDOK)
	{
		CString strPath = dlg.GetPathName();
		int npos = strPath.ReverseFind('\\');
		m_strpath = strPath.Left(npos);
		int npos2 = m_strpath.ReverseFind('\\');
		CString str = m_strpath.Mid(npos2 + 1, abs(npos - npos2));

		SetWindowText(str);
		HTuple hv_Width,  hv_Height;
		try
		{
			ReadImage(&hv_image, HTuple(strPath));
			Rgb1ToGray(hv_image, &hv_image);
			CRect	rc;
			GetDlgItem(IDC_IMAGE_VIEW)->GetClientRect(&rc);
			GetImageSize(hv_image, &hv_Width, &hv_Height);

			/*Row0 = 0;
			Row1 = hv_Height;
			Col0 = (hv_Width - hv_Height*rc.Width() / rc.Height()) / 2;
			Col1 = (hv_Width + hv_Height*rc.Width() / rc.Height()) / 2;*/

			Row0 = (hv_Height - hv_Width * rc.Height() / rc.Width()) / 2;
			Row1 = (hv_Height + hv_Width * rc.Height() / rc.Width()) / 2;
			Col0 = 0;
			Col1 = hv_Width;
			SetPart(m_hvWindow, Row0, Col0, Row1, Col1);
			DispObj(hv_image, m_hvWindow);
		}
		catch (...)
		{
		}
		m_bIsReadImage = TRUE;
	}
	UpdateUI();
}

//2、显示提取的纸杯区域
void CDiaTrainTG::OnBnClickedButton11()
{
	HTuple hv_Exception, hv_ErrMsg, hv_ErrMsg1;
	try
	{
		HTuple  hv_HomMat2D, hv_Exception, hv_ErrMsg, hv_ErrMsg1, ho_width, ho_height, hv_Row1, hv_Column1, hv_Row2, hv_Column2, hv_ModelRegionArea, hv_ModelRow, hv_ModelColumn, hv_area, rowRef, colRef;
		ClearWindow(m_hvWindow);
		DispObj(hv_image, m_hvWindow);
		CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
		GetImageSize(hv_image, &ho_width, &ho_height);
		SetSystem("border_shape_models", "false");
		CHalconTool::disp_message(m_hvWindow, "请画第一个模板匹配区域,右击完成", "window", 30, 10, "red", "true");
		SetColor(m_hvWindow, "red");

		HObject _TmpRegion1, _TmpRegion2, ho_TemplateImage, ho_ModelContours, ho_TransContours, ho_ImageReduced;
		DrawRectangle1(m_hvWindow, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
		GenRectangle1(&_TmpRegion1, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
		CHalconTool::disp_message(m_hvWindow, "请画第二个模板匹配区域,右击完成", "window", 30, 10, "blue", "true");
		DrawRectangle1(m_hvWindow, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
		GenRectangle1(&_TmpRegion2, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
		Union2(_TmpRegion1, _TmpRegion2, &ho_RegionModelShape);

		ReduceDomain(hv_image, ho_RegionModelShape, &ho_TemplateImage);
		if (m_nProductIsCircle)
		{
			CreateScaledShapeModel(ho_TemplateImage, "auto", HTuple(-10).TupleRad(), HTuple(10).TupleRad(),
				"auto", 0.9, 1.1, "auto", "auto", "use_polarity", "auto", "auto", &hv_ShapeModelID);
		}
		else
		{
			CreateScaledShapeModel(ho_TemplateImage, "auto", HTuple(0).TupleRad(), HTuple(360).TupleRad(),
				"auto", 0.9, 1.1, "auto", "auto", "use_polarity", "auto", "auto", &hv_ShapeModelID);
		}
		/*CreateScaledShapeModel(ho_TemplateImage, 6, HTuple(-20).TupleRad(), HTuple(20).TupleRad(),
			"auto", 0.95, 1.05, "auto", "auto", "use_polarity", ((HTuple(25).Append(30)).Append(5)), 9, &hv_ShapeModelID);*/
		
		GetShapeModelContours(&ho_ModelContours, hv_ShapeModelID, 1);
		AreaCenter(ho_RegionModelShape, &hv_ModelRegionArea, &hv_ModelRow, &hv_ModelColumn);
		VectorAngleToRigid(0, 0, 0, hv_ModelRow, hv_ModelColumn, 0, &hv_HomMat2D);
		AffineTransContourXld(ho_ModelContours, &ho_TransContours, hv_HomMat2D);
		DispObj(hv_image, m_hvWindow);
		SetDraw(m_hvWindow, "margin");
		SetColor(m_hvWindow, "red");
		DispObj(ho_RegionModelShape, m_hvWindow);
		DispObj(ho_TransContours, m_hvWindow);

		//找产品区域
		HObject ho_Region, ho_ConnectedRegions, ho_RegionSelected, RegionProductErosionTemp, ho_ImagePart, ho_RegionCompareMoved;
		CHalconTool::disp_message(m_hvWindow, "请画产品位置（所画区域均参与训练）,右击完成", "window", 30, 10, "red", "true");
		DrawRectangle1(m_hvWindow, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
		GenRectangle1(&RegionProductRect, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
		AreaCenter(RegionProductRect, &hv_area, &rowRef, &colRef);
		ReduceDomain(hv_image, RegionProductRect, &ho_ImageReduced);
		CropDomain(ho_ImageReduced, &ho_ImagePart);
		Threshold(ho_ImagePart, &ho_Region,0, m_nbinaryThresh);//255
		Connection(ho_Region, &ho_ConnectedRegions);
		SelectShapeStd(ho_ConnectedRegions, &ho_RegionSelected, "max_area", 70);
		ClosingCircle(ho_RegionSelected, &RegionProductErosionTemp, 2.5);
		MoveRegion(RegionProductErosionTemp, &ho_RegionCompareMoved, hv_Row1, hv_Column1);
		ErosionCircle(ho_RegionCompareMoved, &RegionProductErosion, 2.5);
		SetColor(m_hvWindow, "green");
		DispObj(RegionProductErosion, m_hvWindow);
	}
	catch (HalconCpp::HException& HDevExpDefaultException)
	{
		HDevExpDefaultException.ToHTuple(&hv_Exception);
		HException::GetExceptionData(hv_Exception, "error_message", &hv_ErrMsg);
		HException::GetExceptionData(hv_Exception, "operator", &hv_ErrMsg1);
		SetTposition(m_hvWindow, 1, 10);
		WriteString(m_hvWindow, hv_ErrMsg);
		NewLine(m_hvWindow);
		WriteString(m_hvWindow, hv_ErrMsg1);
		return;
	}
	CHalconTool::disp_message(m_hvWindow, "创建完成               ", "window", 30, 10, "red", "true");
	m_bIsExtractRegionCup = true;
	UpdateUI();
}



void CDiaTrainTG::OnBnClickedButtonBackAbnTrain()
{
	HTuple hv_fileExist,hv_Files_OK,hv_Selection, hv_ValueWidth, hv_ValueHeight, hv_Area,hv_ModelRow,hv_ModelColumn, hv_Index;
	HTuple hv_Width1,hv_Height1, hv_Row,  hv_Column, hv_Angle,hv_Scale, hv_Score, hv_HomMat2D;
	HObject ho_Image, ho_ImageAffineTrans, ho_ImageReduced,ho_ImagePart;
	HTuple hv_Exception, hv_ErrMsg, hv_ErrMsg1;
	try
	{
		FileExists((HTuple)(m_strpath), &hv_fileExist);
		if (hv_fileExist[0].I() == 0)
		{
			AfxMessageBox("文件夹路径不存在");
		}
		ListFiles((HTuple)(m_strpath), "files", &hv_Files_OK);
		TupleRegexpSelect(hv_Files_OK, "\\.(jpg|jpeg|bmp)", &hv_Selection);//
		HTuple end_val55 = (hv_Selection.TupleLength()) - 1;
		HTuple step_val55 = 1;
		//获取参考点1
		RegionFeatures(RegionProductRect, "width", &hv_ValueWidth);
		RegionFeatures(RegionProductRect, "height", &hv_ValueHeight);
		AreaCenter(ho_RegionModelShape, &hv_Area, &hv_ModelRow, &hv_ModelColumn);
		CreateVariationModel(hv_ValueWidth, hv_ValueHeight, "byte", "standard", &hv_VarModelID);
		for (hv_Index = 0; hv_Index.Continue(end_val55, step_val55); hv_Index += step_val55)
		{
			HTuple  hv_Position, hv_Position2;
			TupleStrstr(HTuple(hv_Selection[hv_Index]), "MeanImage", &hv_Position);
			TupleStrstr(HTuple(hv_Selection[hv_Index]), "VarImage", &hv_Position2);
			if (0 != (HTuple(int(hv_Position != -1)).TupleOr(int(hv_Position2 != -1))))
			{
				continue;
			}
			ReadImage(&ho_Image, HTuple(hv_Selection[hv_Index]));
			GetImageSize(ho_Image, &hv_Width1, &hv_Height1);
			if (m_nProductIsCircle)
			{
				FindScaledShapeModel(ho_Image, hv_ShapeModelID, HTuple(-10).TupleRad(), HTuple(1).TupleRad(),
					0.95, 1.05, 0.5, 1, 0.5, "least_squares", 0, 0.9, &hv_Row, &hv_Column, &hv_Angle, &hv_Scale, &hv_Score);
			}
			else
			{
				FindScaledShapeModel(ho_Image, hv_ShapeModelID, HTuple(0).TupleRad(), HTuple(360).TupleRad(),
					0.95, 1.05, 0.5, 1, 0.5, "least_squares", 0, 0.9, &hv_Row, &hv_Column, &hv_Angle, &hv_Scale, &hv_Score);
			}

			if (0 != (int((hv_Row.TupleLength()) == 0)))
			{
				CHalconTool::disp_message(m_hvWindow, "匹配失败", "window", 20, 20, "black", "true");
				continue;
			}
			VectorAngleToRigid(hv_Row, hv_Column, hv_Angle, hv_ModelRow, hv_ModelColumn, 0, &hv_HomMat2D);
			AffineTransImage(ho_Image, &ho_ImageAffineTrans, hv_HomMat2D, "constant", "false");

			ReduceDomain(ho_ImageAffineTrans, RegionProductRect, &ho_ImageReduced);

			HObject ho_Domain;
			CropDomain(ho_ImageReduced, &ho_ImagePart);
			GetDomain(ho_ImagePart, &ho_Domain);
			AreaCenter(ho_Domain, &hv_Area, &hv_Row, &hv_Column);

			//GetShapeModelContours(&ho_ModelContours, hv_ModelID, 1);
			//VectorAngleToRigid(0, 0, 0, hv_Row, hv_Column, 0, &hv_HomMat2D);
			//AffineTransContourXld(ho_ModelContours, &ho_ContoursAffineTrans, hv_HomMat2D);
			try
			{
				TrainVariationModel(ho_ImagePart, hv_VarModelID);
			}
			catch (HalconCpp::HException& HDevExpDefaultException)
			{
				
				CHalconTool::set_display_font(m_hvWindow, 13, "mono", "true", "false");
				HDevExpDefaultException.ToHTuple(&hv_Exception);
				HException::GetExceptionData(hv_Exception, "error_message", &hv_ErrMsg);
				HException::GetExceptionData(hv_Exception, "operator", &hv_ErrMsg1);
				SetTposition(m_hvWindow, 90, 0);
				WriteString(m_hvWindow, hv_ErrMsg);
				NewLine(m_hvWindow);
				WriteString(m_hvWindow, hv_ErrMsg1);
			}

		}

		GetVariationModel(&ho_MeanImage, &ho_VarImage, hv_VarModelID);
		ClearVariationModel(hv_VarModelID);
	}
	catch (HalconCpp::HException& HDevExpDefaultException)
	{
		HDevExpDefaultException.ToHTuple(&hv_Exception);
		HException::GetExceptionData(hv_Exception, "error_message", &hv_ErrMsg);
		HException::GetExceptionData(hv_Exception, "operator", &hv_ErrMsg1);
		SetTposition(m_hvWindow, 1, 10);
		WriteString(m_hvWindow, hv_ErrMsg);
		NewLine(m_hvWindow);
		WriteString(m_hvWindow, hv_ErrMsg1);
		return;
	}
	CHalconTool::disp_message(m_hvWindow, "训练完成  ", "window", 60, 10, "red", "true");
	m_bIsTrainFibished = true;
	UpdateUI();
	return;
}

void CDiaTrainTG::UpdateUI()
{
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	GetDlgItem(IDC_BUTTON11)->EnableWindow(m_bIsReadImage);//IDC_BUTTON18
	GetDlgItem(IDC_BTN_SAVE2)->EnableWindow(m_bIsReadImage);//IDC_BUTTON18
	GetDlgItem(IDC_BUTTON_Interference)->EnableWindow(m_bIsReadImage);//IDC_BUTTON18
	GetDlgItem(IDC_BUTTON_BACK_ABN_TRAIN)->EnableWindow(m_bIsReadImage  && m_bIsExtractRegionCup);
	GetDlgItem(IDC_BUTTON_MeanImage)->EnableWindow(m_bIsReadImage && m_bIsExtractRegionCup && m_bIsTrainFibished);
	GetDlgItem(IDC_BUTTON_VarImage)->EnableWindow(m_bIsReadImage  && m_bIsExtractRegionCup && m_bIsTrainFibished);
	GetDlgItem(IDC_BTN_SAVE)->EnableWindow(m_bIsReadImage && m_bIsExtractRegionCup && m_bIsTrainFibished);
}

//保存模型
void CDiaTrainTG::OnBnClickedBtnSave()
{
	HObject ho_ImageConverted;
	CDefectInspectionSystemDlg* pDia = CDefectInspectionSystemDlg::s_pDialog;
	//CFileDialog	dlg(FALSE, NULL, "VariationModel.vam", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "模型文件| *.vam|所有文件|*.*|");
	CFileDialog	dlg(FALSE, NULL, "ho_ModelID", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "所有文件|*.*|");
	dlg.m_ofn.lpstrInitialDir = theApp.m_strFilePath;
	HTuple area, row, col;
	if (dlg.DoModal() == IDOK)
	{
		CString	tmpstr = dlg.GetPathName();

		if (hv_ShapeModelID.TupleLength() > 0)
		{
			try
			{
				WriteShapeModel(hv_ShapeModelID, (HTuple)(tmpstr));
				CString str;
				str = tmpstr.Left(tmpstr.ReverseFind('\\') + 1);
				WriteRegion(ho_RegionModelShape, HTuple(str + "ho_RegionModelShape"));
				WriteRegion(ho_RegionInterference, HTuple(str + "ho_RegionInterference"));
				WriteRegion(RegionProductRect, HTuple(str + "RegionProductRect"));
				WriteRegion(RegionProductErosion, HTuple(str + "RegionProductErosion"));
				WriteImage(ho_MeanImage, "bmp", 0, HTuple(str + "ho_MeanImage"));
				ConvertImageType(ho_VarImage, &ho_ImageConverted, "byte");
				WriteImage(ho_ImageConverted, "bmp", 0, HTuple(str + "ho_VarImage"));
				ClearShapeModel(hv_ShapeModelID);

			}
			catch (HalconCpp::HException& HDevExpDefaultException)
			{

			}

		}
	}
	UpdateUI();
}


void CDiaTrainTG::OnClose()
{
	m_bIsReadImage = FALSE;
	m_bIsExtractRegionCup = FALSE;
	m_bIsAutoThresh = FALSE;
	m_bIsTrainFibished = FALSE;
	m_IsDrawMirror = FALSE;
	nIndexShowImageBack = 0;
	CDialogEx::OnClose();
}


BOOL CDiaTrainTG::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	// TODO:  在此添加消息处理程序代码和/或调用默认值
	if (hv_image.Key() == UNDEF_IMAGE || hv_image.Key() == UNDEF_IMAGE)
		return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
	CRect	WndRect;
	HTuple	ImagePtX, ImagePtY;
	HTuple	Row0_1, Col0_1, Row1_1, Col1_1;
	double	Scale = 0.1;
	GetDlgItem(IDC_IMAGE_VIEW)->GetWindowRect(&WndRect);
	if (WndRect.PtInRect(pt))
	{
		if (zDelta > 0)
		{
			ImagePtX = Col0 + (HTuple)((pt.x - WndRect.left) / (WndRect.Width() - 1.0) * (Col1 - Col0));
			ImagePtY = Row0 + (HTuple)((pt.y - WndRect.top) / (WndRect.Height() - 1.0) * (Row1 - Row0));
			Row0_1 = ImagePtY - (HTuple)(1 / (1 - Scale) * (ImagePtY - Row0));
			Row1_1 = ImagePtY - (HTuple)(1 / (1 - Scale) * (ImagePtY - Row1));
			Col0_1 = ImagePtX - (HTuple)(1 / (1 - Scale) * (ImagePtX - Col0));
			Col1_1 = ImagePtX - (HTuple)(1 / (1 - Scale) * (ImagePtX - Col1));
			Row0 = Row0_1;
			Col0 = Col0_1;
			Row1 = Row1_1;
			Col1 = Col1_1;
			SetPart(m_hvWindow, Row0, Col0, Row1, Col1);
			ClearWindow(m_hvWindow);
			switch (nIndexShowImageBack)
			{
			case 0:
				DispObj(hv_image, m_hvWindow);
				break;
			case 1:
				DispObj(ho_MeanImage, m_hvWindow);
				break;
			case 2:
				DispObj(ho_VarImage, m_hvWindow);
				break;
			default:
				DispObj(hv_image, m_hvWindow);
				break;
			}
		}
		else
		{
			ImagePtX = Col0 + (HTuple)((pt.x - WndRect.left) / (WndRect.Width() - 1.0) * (Col1 - Col0));
			ImagePtY = Row0 + (HTuple)((pt.y - WndRect.top) / (WndRect.Height() - 1.0) * (Row1 - Row0));
			Row0_1 = ImagePtY - (HTuple)(1 / (1 + Scale) * (ImagePtY - Row0));
			Row1_1 = ImagePtY - (HTuple)(1 / (1 + Scale) * (ImagePtY - Row1));
			Col0_1 = ImagePtX - (HTuple)(1 / (1 + Scale) * (ImagePtX - Col0));
			Col1_1 = ImagePtX - (HTuple)(1 / (1 + Scale) * (ImagePtX - Col1));
			Row0 = Row0_1;
			Col0 = Col0_1;
			Row1 = Row1_1;
			Col1 = Col1_1;
			SetPart(m_hvWindow, Row0, Col0, Row1, Col1);
			ClearWindow(m_hvWindow);
			switch (nIndexShowImageBack)
			{
			case 0:
				DispObj(hv_image, m_hvWindow);
				break;
			case 1:
				DispObj(ho_MeanImage, m_hvWindow);
				break;
			case 2:
				DispObj(ho_VarImage, m_hvWindow);
				break;
			default:
				DispObj(hv_image, m_hvWindow);
				break;
			}
		}
	}
	return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
}




void CDiaTrainTG::OnBnClickedButtonMeanimage()
{
	nIndexShowImageBack = 1;
	ClearWindow(m_hvWindow);
	DispObj(ho_MeanImage, m_hvWindow);
	UpdateUI();
}


void CDiaTrainTG::OnBnClickedButtonVarimage()
{
	nIndexShowImageBack = 2;
	ClearWindow(m_hvWindow);
	DispObj(ho_VarImage, m_hvWindow);
	UpdateUI();
}


void CDiaTrainTG::OnBnClickedButtonInterference()
{
	HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2;
	CHalconTool::disp_message(m_hvWindow, "请画第一个易误检区域,右击完成", "window", 30, 10, "red", "true");
	SetColor(m_hvWindow, "blue");

	HObject _TmpRegion1, _TmpRegion2, ho_TemplateImage, ho_ModelContours, ho_TransContours, ho_ImageReduced;
	DrawRectangle1(m_hvWindow, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
	GenRectangle1(&_TmpRegion1, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
	CHalconTool::disp_message(m_hvWindow, "请画第二个易误检区域,右击完成", "window", 30, 10, "blue", "true");
	DrawRectangle1(m_hvWindow, &hv_Row1, &hv_Column1, &hv_Row2, &hv_Column2);
	GenRectangle1(&_TmpRegion2, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
	Union2(_TmpRegion1, _TmpRegion2, &ho_RegionInterference);
	UpdateUI();
}
